﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using MyLibrary.Json;
using MyLibrary.Data.Builder;
using MyLibrary.Data.Builder.Config;


namespace MyLibrary.Data.Builder.Component
{
    class ConditionNormal : ConditionComponentBase
    {
        private string _dbConnKey = String.Empty;
        /// <summary>
        /// 报表数据库的连接字符串键名
        /// </summary>
        public override string DBConnectionKey
        {
            get { return _dbConnKey; }
            set { _dbConnKey = value; }
        }

        private ReportCondition _condition = null;
        /// <summary>
        /// 下拉框中的数据源类型
        /// </summary>
        public override ReportCondition ReportCondition
        {
            get { return _condition; }
            set { _condition = value; }
        }

        /// <summary>
        /// 添加ASP控件
        /// </summary>
        /// <param name="holder">控件容器</param>
        public override void DrawASPComponent(PlaceHolder holder)
        {
            Label title = new Label();
            if (!String.IsNullOrEmpty(_condition.ConditionTitle))
            {
                title.Text = "&nbsp;" + _condition.ConditionTitle + "：";
                holder.Controls.Add(title);
            }
            TextBox textBox = new TextBox();
            if (!String.IsNullOrEmpty(_condition.ConditionID))
                textBox.ID = _condition.ConditionID;
            else
                textBox.ID = Guid.NewGuid().ToString();
            textBox.Width = 85;
            if (!String.IsNullOrEmpty(_condition.ConditionContent))
                textBox.Text = _condition.ConditionContent;
            holder.Controls.Add(textBox);
        }

        public override string DrawHTMLComponent()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("&nbsp;" + _condition.ConditionTitle + "：<input type='textbox' id='" + _condition.ConditionID + "'")
                .Append(" style='width:85px' value='" + _condition.ConditionContent + "'/>");
            return builder.ToString();
        }
    }
}
